class Solution(object):
    def deleteAndEarn(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        t = [0] * 10000
        for num in nums:
            t[num - 1] += 1
        last1 = t[0]
        last2 = 0
        for i in range(1, 10000):
            last1, last2 = last2 + t[i] * (i + 1), max(last1, last2)
        return max(last1, last2)


data = Solution()
nums = [2, 2, 3, 3, 3, 4]
print(data.deleteAndEarn(nums))
